package com.danny.Controller;

import com.danny.mapper.VipMapper;
import com.danny.pojo.Vip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class VipController {
    @Autowired
    private VipMapper vipMapper;
    @GetMapping("queryAllVip")
    public List<Vip> queryAllVip(){
        return vipMapper.queryAllVip();
    }
    @GetMapping ("queryVipLimit")
    public List<Vip> queryVipLimit(String VipName,int page,int pageSize){
        return  vipMapper.queryVipLimit(VipName,page,pageSize);
    }
    @GetMapping("queryVipLimitByNoParam")
    public List<Vip> queryVipLimitByNoParam(int page,int pageSize){
        return vipMapper.queryVipLimitByNoParam(page,pageSize);
    }
    @GetMapping("addVip")
    public String addVip(Vip admin){

        List<Vip> list=vipMapper.queryAllVip();
        for(Vip vip:list){
            if(vip.getTel().equals(admin.getTel())){
                System.out.println("存在重复会员！");
                return "error";
            }
        }
        if(vipMapper.addVip(admin)<=0)return "error";
        return "inserted";
    }
    @GetMapping("updateVip")
    public String updateVip(Vip admin){
        if(vipMapper.updateVip(admin)>0)return "updated";
        return  "error";
    }
    @GetMapping("deleteVipById")
    public String deleteVipById(int id){
        if(vipMapper.deleteVipById(id)>0)return "deleted";
        return "error";
    }

    @GetMapping("vipCount")
    public  int vipCount(){
        return vipMapper.vipCount();
    }

    @GetMapping("vipCountHasInput")
    public  int vipCountHasInput(String VipName){
        return vipMapper.vipCountHasInput(VipName);
    }

}
